function [shortest_paths] = get_paths(bio, basin_id, comp_edgelist, varargin)
% varargin{1} = whether or not to write paths = 0/1; note that paths are currently
% indices and not BASIN ids. Need to convert to BASIN IDs.
% varargin{2} = whether or not to use weights - if any

t = cputime;
write_paths = 0;
if (nargin>3 && isscalar(varargin{1}) && (varargin{1} == 1))
    write_paths = 1;
   % if (exist(strcat(comp_edgelist,'paths.txt'), 'file'))
   %     fid = fopen(strcat(comp_edgelist,'paths-no-ns.txt'), 'w');
   % else
        fid = fopen(strcat(comp_edgelist,'paths.txt'), 'w');
   % end
end


edges = importdata(comp_edgelist);

numEdges = length(edges);

shortest_paths = ones(numEdges, 1)*-1;
for i = 1:numEdges
    srcID = find(basin_id==edges(i,1));
    destID = find(basin_id==edges(i,2));
    dist = -1;
    if (isscalar(srcID) && isscalar(destID))
        % default is directed graph. set 'Directed' false incase I need
        % undirected
        if nargin>4 && isvector(varargin{2})
            [dist, path, ~] = graphshortestpath(bio, srcID, destID, 'WEIGHTS', varargin{2});
        else
            [dist, path, ~] = graphshortestpath(bio, srcID, destID);
        end
        if (~(isscalar(dist)) || ~(isfinite(dist)))
            dist = -1;
        end
        shortest_paths(i,1) = dist;
    end
        if (write_paths)
            fprintf(fid, '%d-%d\t%d\t',edges(i,1), edges(i,2), dist);
            if (dist > 0)
                for j = 1:length(path)
                    fprintf(fid, '%d\t', basin_id(path(1,j)));
                end
            end
            fprintf(fid, '\n');
        end
end

if (write_paths)
    fclose(fid);
end

e = (cputime - t)/60
% Sample Usage:
% [BioGraphWithWeights, WeightLabels, Weights] = edgeList2sparse('/Archana/Projects/Currently Working/BASINkStep/Data/BASIN_DBFiles/DistinctInteractionsWithWeight.txt');
%
% %Getting all paths
% BayesShortestPaths = get_paths(BioGraph, BasinIDsBioGraph, '/Archana/Projects/Currently Working/BASINkStep/Data/TN Networks/BasinBayesEdge.txt', 1);
% BayesWeightedShortestPaths = get_paths(BioGraphWithWeights, BasinIDsBioGraphWeight, '/Archana/Projects/Currently Working/BASINkStep/Data/TN Networks/BasinBayesEdge.txt', 0, Weights);
%
% CMShortestPaths = get_paths(BioGraph, BasinIDsBioGraph, '/Archana/Projects/Currently Working/BASINkStep/Data/TN Networks/BasinCM001EdgeList.txt', 1);
% CMWeightedShortestPaths = get_paths(BioGraphWithWeights, BasinIDsBioGraphWeight, '/Archana/Projects/Currently Working/BASINkStep/Data/TN Networks/BasinCM001EdgeList.txt', 0, Weights);
%
% ArShortestPaths = get_paths(BioGraph, BasinIDsBioGraph, '/Archana/Projects/Currently Working/BASINkStep/Data/TN Networks/BasinAracneEdgeList1e-7.txt', 1);
% ArWeightedShortestPaths = get_paths(BioGraphWithWeights, BasinIDsBioGraphWeight, '/Archana/Projects/Currently Working/BASINkStep/Data/TN Networks/BasinAracneEdgeList1e-7.txt', 0, Weights);